import { WuXingBasePanel } from "./WuXingBasePanel";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../resource/ImagesConst";
import { WuXingGradeEquipList } from "./WuXingGradeEquipList";
import { GImageBitmap } from "../../../../com/mui/controls/GImageBitmap";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { BaseItem } from "../common/BaseItem";
import { WuXingGradeUpItem } from "./WuXingGradeUpItem";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { PetProcessBar } from "../pet/PetProcessBar";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { PetMingMsgRollTips } from "../pet/ming/PetMingMsgRollTips";
import { WuXingGradeEquipItem } from "./WuXingGradeEquipItem";
import { ItemData } from "../../resource/info/ItemData";
import { WuXingRule } from "../../rules/WuXingRule";
import { MsgManager } from "../../manager/MsgManager";
import { Cache } from "../../cache/Cache";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class WuXingGradeUpPanel
    
    export  class WuXingGradeUpPanel extends WuXingBasePanel
    {
        constructor(arg1: int=428, arg2: int=438)
        {
            super(arg1, arg2);
            return;
        }

        protected /* override */ initUI(): void
        {
            super.initUI();
            var loc1=ResouceConst.getScaleBitmap(ImagesConst.VSpliteLine);
            loc1.x = this._bg2Width + 3;
            loc1.y = _bg1.y;
            loc1.height = _bg1.height;
            addChild(loc1);
            this._itemList = new WuXingGradeEquipList();
            this._itemList.x = loc1.x + 10;
            this._itemList.y = _bg1.y + 40;
            this._itemList.addEventListener(flash.events.MouseEvent.CLICK, this.onItemListClickHandler);
            addChild(this._itemList);
            addChild(new GImageBitmap(ImagesConst.LongBg, 2, 2));
            this._quickLookFont = new GImageBitmap("Label_jipingyulang.png");
            this._quickLookFont.x = _bg1.x + 41;
            this._quickLookFont.y = 10;
            addChild(this._quickLookFont);
            this._quickLookBg = GlobalClass.getBitmap(ImagesConst.equipment_boarder);
            this._quickLookBg.x = this._quickLookFont.x + 20;
            this._quickLookBg.y = this._quickLookFont.y + 30;
            addChild(this._quickLookBg);
            this._quickLookItem = new BaseItem();
            this._quickLookItem.setSize(32, 32);
            this._quickLookItem.x = this._quickLookBg.x + 10;
            this._quickLookItem.y = this._quickLookBg.y + 10;
            this._quickLookItem.isDragAble = false;
            addChild(this._quickLookItem);
            this._optItem1 = new WuXingGradeUpItem(true);
            this._optItem1.x = _bg1.x + this._bg2Width / 2 - this._optItem1.width - 40;
            this._optItem1.y = 102;
            addChild(this._optItem1);
            this._optItem1.addEventListener(flash.events.MouseEvent.CLICK, this.onOptItem1ClickHandler);
            this._optItem2 = new WuXingGradeUpItem();
            this._optItem2.x = _bg1.x + this._bg2Width / 2 + 40;
            this._optItem2.y = this._optItem1.y;
            addChild(this._optItem2);
            this._arrowBg = new GImageBitmap(ImagesConst.wxGradeArrow);
            this._arrowBg.x = (this._bg2Width - 53) / 2;
            this._arrowBg.y = this._optItem1.y + 35;
            addChild(this._arrowBg);
            this._hLine = GlobalClass.getScaleBitmap(ImagesConst.SplitLine);
            this._hLine.x = 5;
            this._hLine.y = 195;
            this._hLine.width = this._bg2Width - 10;
            addChild(this._hLine);
            this._degreeInfo = ObjCreate.createTextField(Language.getString(26308) + "：", _bg1.x + 15, this._hLine.y + 38, 100, 20, this);
            this._degreeBar = new PetProcessBar(ImagesConst.PurpleBar10, 177, 12);
            this._degreeBar.move(this._degreeInfo.x + this._degreeInfo.textWidth + 2, this._degreeInfo.y + 2);
            this._degreeBar.setValue(0, 0);
            addChild(this._degreeBar);
            this._optBtn1 = ObjCreate.createGButton(Language.getString(26309), 0, this._hLine.y + 62, 74, 24, this, "ButtonRed");
            this._optBtn1.x = _bg1.x + this._bg2Width / 2 - this._optBtn1.width / 2;
            this._optBtn1.addEventListener(flash.events.MouseEvent.CLICK, this.onOptBtn1ClickHandler);
            this._optBtn2 = ObjCreate.createGButton(Language.getString(26310), 0, this._optBtn1.y, 74, 24, this, "ButtonRed");
            this._optBtn2.x = _bg1.x + this._bg2Width / 2 + 20;
            this._optBtn2.addEventListener(flash.events.MouseEvent.CLICK, this.onOptBtn2ClickHandler);
            this._juhunCountBmp = new Object /* flash.display.Bitmap */();
            this._juhunCountBmp.x = this._optBtn1.x + this._optBtn1.width + 8;
            this._juhunCountBmp.y = this._optBtn1.y + 2;
            addChild(this._juhunCountBmp);
            this._juhunCountTxt = ObjCreate.createTextField(Language.getString(26408), this._juhunCountBmp.x + 22, this._juhunCountBmp.y + 7, 210, 20, this);
            this._juhunCountTxt.textColor = 16776960;
            this._juhunCountTxt.mouseEnabled = false;
            this._line = ResouceConst.getScaleBitmap(ImagesConst.SplitLine);
            this._line.x = _bg1.x + 5;
            this._line.y = 290;
            this._line.width = this._bg2Width - 10;
            addChild(this._line);
            this._effectStartPoint = new Object /* flash.geom.Point */();
            this._effectEndPoint = new Object /* flash.geom.Point */();
            LoaderHelp.addResCallBack(ResFileConst.wuxing, this.onWuXingBgLoadedHandler);
            this._msgRollTips = new PetMingMsgRollTips();
            this._msgRollTips.x = this._optBtn1.x;
            this._msgRollTips.y = this._optBtn1.y - 20;
            this.addChild(this._msgRollTips);
            return;
        }

        protected onWuXingBgLoadedHandler(): void
        {
            this._juhunCountBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.wxJuHunIcon);
            return;
        }

        protected onItemListClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as WuXingGradeEquipItem;
            this.selectedItem(loc1);
            return;
        }

        protected selectedItem(arg1: WuXingGradeEquipItem): void
        {
            if (arg1 && arg1.item) 
            {
                if (!this.optAble(arg1.item)) 
                {
                    this.clear();
                    return;
                }
                if (arg1 != this._lastItem) 
                {
                    arg1.mouseDown(true);
                    this.updateCurrentItem(arg1.item);
                    this.updateProcessBar(arg1.item);
                    this.updateMaxGradeItem(arg1.item);
                    if (this._lastItem) 
                    {
                        this._lastItem.mouseDown(false);
                    }
                    this._lastItem = arg1;
                }
            }
            return;
        }

        protected optAble(arg1: ItemData): Boolean
        {
            if (!WuXingRule.wxGradeAble(arg1)) 
            {
                MsgManager.showRollTipsMsg(Language.getString(26305));
                return false;
            }
            return true;
        }

        protected onOptBtn1ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            return;
        }

        protected onOptBtn2ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            return;
        }

        protected updateCurrentItem(arg1: ItemData, arg2: Boolean=false): void
        {
            if (arg1) 
            {
                if (!arg2 && this._currentItem && this._currentItem == arg1) 
                {
                    return;
                }
                this._currentItem = arg1;
                this._nextItem = this.getNextItem(arg1);
            }
            else 
            {
                this.clear();
            }
            return;
        }

        protected getNextItem(arg1: ItemData): ItemData
        {
            return null;
        }

        protected updateProcessBar(arg1: ItemData): void
        {
            this._lastBarValue = this._degreeBar.value;
            this._lastBarTotal = this._degreeBar.totalValue;
            return;
        }

        protected updateMaxGradeItem(arg1: ItemData): void
        {
            return;
        }

        protected onOptItem1ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._lastItem) 
            {
                this._lastItem.mouseDown(false);
                this._lastItem = null;
            }
            if (this._currentItem) 
            {
                this.clear();
            }
            return;
        }

        protected clear(): void
        {
            if (this._lastItem) 
            {
                this._lastItem.mouseDown(false);
                this._lastItem = null;
            }
            this._currentItem = null;
            this._lastEffectItem = null;
            this._quickLookItemData = null;
            this._optItem1.dispose();
            this._optItem2.dispose();
            this._quickLookItem.itemData = null;
            this._quickLookItem.toolTipData = null;
            this._degreeBar.setValue(0, 0);
            return;
        }

        public /* override */ updateRolePack(): void
        {
            var loc1=null;
            super.updateRolePack();
            if (this._lastItem && this._lastItem.item) 
            {
                loc1 = this._lastItem.item.uid;
            }
            this._items = Cache.instance.pack.rolePackCache.getEquipItems();
            this._itemList.updateData(this._items);
            if (loc1 != null) 
            {
                this._lastItem = this._itemList.getListItemByItemCode(loc1);
            }
            if (this._currentItem) 
            {
                this._currentItem = Cache.instance.pack.rolePackCache.getItemDataByUid(this._currentItem.uid);
                this.updateCurrentItem(this._currentItem, true);
                this.updateProcessBar(this._currentItem);
                if (this._currentItem && loc1 == this._currentItem.uid) 
                {
                    this._lastItem.mouseDown(true);
                }
            }
            return;
        }

        public /* override */ onGradeResEffect(): void
        {
            super.onGradeResEffect();
            this._lastEffectItem = this._currentItem;
            return;
        }

        public /* override */ onGradeItemReq(arg1: ItemData): void
        {
            super.onGradeItemReq(arg1);
            var loc1=this._itemList.getListItemByItem(arg1);
            this.selectedItem(loc1);
            return;
        }

        public /* override */ dispose(): void
        {
            if (this._lastItem) 
            {
                this._lastItem.mouseDown(false);
            }
            this.clear();
            return;
        }

        public /* override */ showMsg(arg1: string): void
        {
            this._msgRollTips.showMsg(arg1, 1);
            return;
        }

        protected /* var */_lastItem: WuXingGradeEquipItem;

        protected /* var */_currentItem: ItemData;

        protected /* var */_nextItem: ItemData;

        protected /* var */_lastEffectItem: ItemData;

        protected /* var */_quickLookItemData: ItemData;

        protected /* var */_lastBarTotal: int;

        protected /* var */_effectStartPoint: Object /* flash.geom.Point */;

        protected /* var */_effectEndPoint: Object /* flash.geom.Point */;

        protected /* var */_msgRollTips: PetMingMsgRollTips;

        protected /* var */_lastBarValue: int;

        protected /* var */_bg2Width: int=305;

        protected /* var */_quickLookBg: Object /* flash.display.Bitmap */;

        protected /* var */_quickLookFont: GImageBitmap;

        protected /* var */_quickLookItem: BaseItem;

        protected /* var */_arrowBg: GImageBitmap;

        protected /* var */_optItem1: WuXingGradeUpItem;

        protected /* var */_optItem2: WuXingGradeUpItem;

        protected /* var */_hLine: ScaleBitmap;

        protected /* var */_degreeInfo: Object /* flash.text.TextField */;

        protected /* var */_degreeBar: PetProcessBar;

        protected /* var */_optBtn1: GButton;

        protected /* var */_items: Array<any>;

        protected /* var */_optBtn2: GButton;

        protected /* var */_juhunCountBmp: Object /* flash.display.Bitmap */;

        protected /* var */_juhunCountTxt: Object /* flash.text.TextField */;

        protected /* var */_line: ScaleBitmap;

        protected /* var */_itemList: WuXingGradeEquipList;
    }
